package com.ttg.common.enums;

import java.util.Arrays;

/**
 * Description： 划段分批枚举
 * Author: chenyou
 * Date: 2025/10/14 9:33
 * Company: ttg
 * Copyright: Copyright (c) 2025
 */
public enum GradingCutOffEnum {

    CUT_OFF_1_6(new Integer[]{1,2,3,4,5,6},"CUT_OFF_1_6"),
    CUT_OFF_7_11(new Integer[]{7,8,9,10,11},"CUT_OFF_7_11"),
    CUT_OFF_12_13(new Integer[]{12,13},"CUT_OFF_12_13"),
    CUT_OFF_14_16(new Integer[]{14,15,16},"CUT_OFF_14_16"),
    CUT_OFF_17_20(new Integer[]{17,18,19,20},"CUT_OFF_17_20"),
    ;


    // 实例属性：数组引用（推荐 final，内容仍可变）
    private final Integer[] codes;
    private final String value;

    // 构造器：private 可省略，但必须是 private
    GradingCutOffEnum(Integer[] codes,String value) {
        // 防御性拷贝，避免外部修改影响枚举内部状态
        this.codes = codes.clone();
        this.value = value;
    }

    // 只读访问：返回副本，保护内部数组
    public Integer[] getCodes() {
        return codes.clone();
    }

    public String getValue(){
        return value;
    }

    public static GradingCutOffEnum getByCode(Integer code){
        for(GradingCutOffEnum cutOffEnum : GradingCutOffEnum.values()){
            boolean result = Arrays.stream(cutOffEnum.getCodes()).anyMatch(o -> o.equals(code));
            if(result){
                return cutOffEnum;
            }
        }
        return null;
    }
}
